
/**
 * 提示框 
 * @param {Object} str
 * @param {Object} callback
 */
function showTips(str, callback) {
	
	safeRemoveBox();
	
	var $dom = $('<div class="tips-box" id="tipsBox">\
				   <div class="tips-wrapper">\
						<div class="tips-item clearfix">\
							<span class="tip-img"></span>\
							<span class="tip-info"></span>\
						</div>\
						<div class="tips-confirm">\
							<a href="javascript:void(0)" class="tips-btn ___closeBox">确定</a>\
						</div>\
					</div>\
				</div>');
	
	$dom.find('.tip-info').html(str);
	
	$.XYTipsWindow({
		___title:"中奖提示框",
		___content:"text:" + $dom.html(),
		___showbg:true,
		___drag:"___boxTitle",
		___width:"400px",
		___height:"200px",
		___boxWrapBdColor:"#666",
		___boxBdColor:"#a5a5a5",
		___fnClose:function(){
			//关闭窗口后执行的函数
			if (typeof callback === 'function') {
				callback();
			}
		}
	});
	
}

//返回顶部
$(function () {
	$("#backToTop").click(function() {
	    $("html,body").animate({scrollTop: 0}, 0);
	    return false;
	});
});

//检查字符数目—— 约定：一个中文字符=两个非中文字符
/**
 * 截取字符数量
 * 检查字符数目—— 约定：一个中文字符=两个非中文字符
 * 
 * @param {String} str ：需要限制字符的文本字符串
 * @param {Number} num ：限制的文本字符数量
 * @return {String}：经过截取的新文本
 */
function getStrWithLength(str, num) {
	var count = 0,
		resStr = '',
		tempChar;
	
	for (var i = 0; i < str.length; i++) {
		tempChar = str.charAt(i);
		//检测中文字符
		if (/^[\u0391-\uFFE5]+$/.test(tempChar)) {
			count += 2;
			if (count > num) {
				return resStr;
			}
		} else {	//非中文字符
			count++;
		}
		resStr += tempChar;
	}
	return resStr;
}

//字符串截取，截取处用...取代
function widthCheck(name, maxLength){
	if(!maxLength){
		maxLength = 20;
	}
	if(name==null||name.length<1){
		return "";
	}
	var w = 0;//字符串长度，一个汉字长度为2
	var s = 0;//汉字个数
	var p = false;//判断字符串当前循环的前一个字符是否为汉字
	var b = false;//判断字符串当前循环的字符是否为汉字
	var nameSub;
	for (var i=0; i<name.length; i++) {
	   if(i>1 && b==false){
	   		p = false;
	   }
	   if(i>1 && b==true){
	   		p = true;
	   }
	   var c = name.charCodeAt(i);
	   //单字节加1
	   if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
	    	w++;
	    	b = false;
	   }else {
	    	w+=2;
	    	s++;
	    	b = true;
	   }
	   if(w>maxLength && i<=name.length-1){
	   		if(b==true && p==true){
	   			nameSub = name.substring(0,i)+"...";
	   		}
	   		if(b==false && p==false){
	   			nameSub = name.substring(0,i-1)+"...";
	   		}
	   		if(b==true && p==false){
	   			nameSub = name.substring(0,i)+"...";
	   		}
	   		if(p==true){
	   			nameSub = name.substring(0,i)+"...";
	   		}
	   		break;
	   }
	}
	if(w<=maxLength){
		return name;
	}
	return nameSub;
}

// 名单滚动
function marqueeUp(containerId, uiId, cloneId) {
	if ($('#' + uiId).find('li').size() > 5) {
		var speed = 40,
			demo = document.getElementById(containerId),		//container
			demo2 = document.getElementById(cloneId),	//clone
			demo1 = document.getElementById(uiId),	//ul
			h0 = demo.offsetHeight,
			h1 = $(demo1).find('li').height();
		demo2.innerHTML = demo1.innerHTML;
		function Marquee() {
		    if (h0 - demo.scrollTop <= -h1) {
		        demo.scrollTop = 0;
		    }
		    else {
		        demo.scrollTop++;
		    }
		}
		var MyMar = setInterval(Marquee, speed);
		demo.onmouseover = function () { 
			clearInterval(MyMar);
		}
		demo.onmouseout = function () { 
			MyMar = setInterval(Marquee, speed); 
		}
	}
}
	
